const values_default = {
  //  type: 'contact'
}

const domain_default = {}

const fields_default = {
  name: null,
  email: null,
  company_id: null,
  title: null,
  country_id: null,
  state_id: null,
  category_id: { name: null, display_name: null },
  child_ids: null,
  property_product_pricelist: null
  //  product_pricelist_item_ids: { name: null, display_name: null }
}

const filterItems = [
  { type: 'date', name: 'date', placeholder: '时间' },
  { type: 'input', name: 'name___like', placeholder: '名称' },

  { type: 'select', name: 'country_id', placeholder: '国家' },
  { type: 'select2', name: 'type', placeholder: '选择类型' },
  { type: 'select', name: 'title', placeholder: '称谓' }
]

const columns = [
  { name: 'company_id__name', type: 'char', label: '公司' },
  { name: 'country_id__name', type: 'char', label: '国家' },
  { name: 'state_id__name', type: 'char', label: '州/省' },
  { name: 'is_company', type: 'boolean', label: 'is_company' },
  { name: 'function', type: 'char', label: 'function' },
  { name: 'bank_ids__names', type: 'char', label: 'Banks' },
  { name: 'category_id__names', type: 'char', label: 'Tags' },
  { name: 'date', type: 'char', label: '日期' },
  { name: 'title__name', type: 'char', label: '称谓' },
  { name: 'name', type: 'char', label: '名称' },
  { name: 'email', type: 'char', label: '邮箱' },
  { name: 'type__name', type: 'char', label: '类型' },
  { name: 'display_name', type: 'char', label: '显示' },
  { name: 'user_id__name', type: 'char', label: '客户经理' },
  { name: 'child_ids__count', type: 'char', label: '联系人' }
  //  { name: 'product_pricelist_item_ids__names', type: 'char', label: '设备清单' }
]

const formItems = [
  { type: 'input', name: 'name', label: '名称' },
  { type: 'input', name: 'email', label: '邮箱', rules: { required: false } },
  { type: 'date', name: 'date', label: '日期', rules: { required: false } },
  { type: 'checkbox', name: 'is_company', label: '是公司么?', text: '是公司' },
  { type: 'select2', name: 'type', label: '类型', placeholder: '选择类型' },
  {
    type: 'select',
    name: 'title',
    label: '称谓',
    placeholder: '称谓',
    rules: { required: false }
  },
  {
    type: 'select',
    name: 'country_id',
    label: '国家地区',
    placeholder: '国家地区',
    rules: { required: false },
    options: {
      order: 'name'
    }
  },
  {
    type: 'select',
    name: 'state_id',
    label: '州/省',
    placeholder: '州/省',
    rules: { required: false },
    options: {
      fields: { country_id: null }
    },

    options_for_select: params => {
      const { temp, options_for_select } = params
      // 设置州省时, 必须先选国家
      return options_for_select.filter(
        item => item.country_id === temp.country_id
      )
    }
  },
  {
    type: 'select',
    name: 'category_id',
    multiple: true,
    rules: { required: false },
    label: 'Tags',
    placeholder: 'Tags',
    default: []
  },

  {
    type: 'select',
    name: 'property_product_pricelist',
    label: '设备清单',
    placeholder: '设备清单',
    rules: { required: false }
  }
]

const child_configs = {
  child_ids: {
    columns: [
      { name: 'parent_id', type: 'char', label: 'parent_id' },
      { name: 'title__name', type: 'char', label: '称谓' },
      { name: 'name', type: 'char', label: '名称' },
      { name: 'email', type: 'char', label: '邮箱' },
      { name: 'mobile', type: 'char', label: '手机' }
    ],

    formItems: [
      { type: 'input', name: 'name', label: '名称' },
      {
        type: 'input',
        name: 'email',
        label: '邮箱',
        rules: { required: false }
      },
      {
        type: 'select',
        name: 'title',
        label: '称谓',
        placeholder: '称谓',
        rules: { required: false }
      }
    ]
  },

  bank_ids: {
    columns: [
      { name: 'acc_number', type: 'char', label: '账号' },
      { name: 'bank_id__name', type: 'char', label: '银行' },
      { name: 'display_name', type: 'char', label: '账号' },
      { name: 'bank_name', type: 'char', label: '银行名称' }
    ],

    formItems: [
      { type: 'input', name: 'acc_number', label: '账号' },
      { type: 'select', name: 'bank_id', label: '银行', placeholder: '银行' }
    ]
  }
}

const Model = {
  // name: 'res.partner',
  configs: {
    values_default,
    domain_default,
    fields_default,
    filterItems,
    columns,
    formItems,
    child_configs
  },

  extend: BaseClass => {
    class ModelClass extends BaseClass {
      global_domain(domain_src = {}) {
        // console.log('this.global_domain in odoo.res.partner')
        const domain = { ...domain_src }
        // const userinfo = self.get_userinfo()
        // const { uid } = userinfo
        // domain.user_id = uid
        return super.global_domain(domain)
      }
      main_partner() {
        return this.call('main_partner')
      }

      find_or_create(email) {
        return this.call('find_or_create', [email])
      }
    }
    return ModelClass
  }
}

export default Model
